﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default5.aspx.cs" Inherits="Default5" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">

    <script src="jquery-1.4.2.min.js" type="text/javascript"></script>

    <script src="json2.js" type="text/javascript"></script>
    <title></title>
    <script type="text/javascript">
        function btn_click() {
            var objEmployees = new Array();
            var objEmployee = {};
            objEmployee.Name = "John";
            objEmployee.Age = "20";
            objEmployee.Address = "Address of John";
            objEmployees[0] = objEmployee;

            objEmployee = {};
            objEmployee.Name = "Andrew";
            objEmployee.Age = "30";
            objEmployee.Address = "Address of Andrew";
            objEmployees[1] = objEmployee;

            var json = JSON.stringify({ "objEmployees": objEmployees , "name" : "Vijay" });
            $.ajax({
                type: "POST",
                url: "Default5.aspx/AddEmployees",
                data: json,
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function(data) {
                    alert(data.d);
                },
                error: function(xhr, ajaxOptions, thrownError) {
                    //handling the error message thrown by c# code
                    var jsonValue = (new Function("return( " + xhr.responseText + " );"))();
                    alert(jsonValue.Message);
                    alert(xhr.status);
                    alert(thrownError);
                }
            });
    }
    
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <input id="Button2" type="button" value="button" onclick="btn_click()"/>
    </div>
    </form>
</body>
</html>
